package com.kfm.base.io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesDemo {

    public static void main(String[] args) {
        Properties prop = new Properties();

        try {
            InputStream in = new FileInputStream("prop/users.properties");
            prop.load(in);


//            Object o = prop.get("friends");
//            System.out.println(o);


//            List<String> list = new ArrayList<>();
//            list.add("张三");
//            list.add("李四");
//
//            prop.setProperty("age", "19");
//            prop.setProperty("gender", "男");
//
//            prop.put("friends", list.toString());
//
//            FileOutputStream fos = new FileOutputStream("prop/users.xml");
//
////            prop.store(fos, "test");
//            prop.storeToXML(fos, "test");
            // 解析 xml  1. SAX  2. DOM4j  3. JDOM

            // 迭代
//            Set<Map.Entry<Object, Object>> entries = prop.entrySet();
//            Iterator<Map.Entry<Object, Object>> iterator = entries.iterator();
//
//            while (iterator.hasNext()){
//                Map.Entry<Object, Object> next = iterator.next();
//                System.out.println(next.getKey() + " , " + next.getValue());
//            }
//            in.close();
//            fos.close();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
